on *:join:#: msg $nick Hello $nick welcome to #
This piece of code will pm the nick who just joined the channel where you are in, with the message "Hello <nickname> welcome to <channelname>".
on *:voice:#: if ($vnick == $me ) msg # Thank you $nick for the voice $+ .
We used the
On Voice
event for this one. And then we checked if the voiced nick is yours
if ($vnick == $me)
. If the condition is true it makes mIRC say "Thank you <nickname of the OP who voiced you> for the voice." in the channel where you were voiced. Now if we hadn't put the condition
if ($vnick == $me)
, mIRC will just go about saying that whenever someone is voiced in the channel, even if it's not you. Notice again how the use of
$vnick
shows you the importance of knowing the mIRC variables.
You can execute multiple commands by using the curly brackets. Here we have an example doing just that. It's taken from the mIRC help file.
on 1:join:#moo:{
msg $nick Welcome $nick to channel #moo!
msg $nick This is a herd-oriented channel, there are calfs present!
msg $nick Please refrain from profaine mooing and/or bleating
msg $nick Mammals enaging in such acts will be promptly demooted
}
The user level is 1; it's used in place of the * we used before. You can use either of them. This time in place of just a #, we've got a specified channel name - #moo. Let's say your nick is MooMan and a guy called Llama join the channel #moo., your mIRC will send the following four messages to Llama.
<MooMan> Welcome Llama to channel #moo!
<MooMan> This is a herd-oriented channel, there are calfs present!
<MooMan> Please refrain from profaine mooing and/or bleating
<MooMan> Mammals enaging in such acts will be promptly demooted
Now here's the code which will pm the guy who just left the channel
on 1:part:#moo:/msg $nick Thanks for grazing with us on #moo!
Those examples were very simple examples of what you can do with remote and the command we executed was only
msg
. Read up the mIRC commands you could do lots more, use your imagination and creativity; instead of MSGing the $nick you could send a notice or open a window, listing all the people who left the channel with their IP and time or set a variable for the nick so that you can use the value in future and so on.
The next example is a deOP protection script; which will OP you back, deOP the guy who deOPd you, ban and kick him/her from the channel with the message "Better luck next time". The code follows below.
on *:deop:#: {
if ($opnick == $me) {
set %wasdeOP 1
set %evilOP $nick
chanserv op # $me
}
}
on *:op:#: {
if (($opnick == $me) && (%wasdeOP)) {
mode # -o %evilOP
mode # +b %evilOP
.timer 1 1 kick # $nick 12Better luck next time!
.timer 1 60 mode # -b %evilOP
unset %wasdeOP
unset %evilOP
}
}
The script consists of two parts: the on deOP and on OP components. When a deOPing takes place, the script checks if the deOPed nick is yours. If it is so, it sets two variables: %wasdeOP with the value 1 and %evilOP with the value the OP which deOPed you. And then it commands ChanServ to OP you. (The IRC network should have ChanServ and you should be a registered OP of the channel or the script won't work). Then comes the on OP part: When someone is OPed the script checks if the OPed nick is yours. If it is true it checks for the variable %wasdeOP which is set when you get deOPed. If both the conditions are true it deOPs, bans and kicks the OP (the nick of the OP is stored in %evilOP) which deOPed you with the message "Better luck next time!". Finally it unsets the two variables it set when you got deOPed.
Please note: The above deOP protection script is not a very efficient one. It was just an example on remote and mIRC scripting in general.
Next we'll write a script that will report of spammers/advertisers on the channel, it's getting more complex this time. It's based on the
On Text
event for the query window. This script could turn out pretty annoying if you really used it or it could back-fire if one of your friends mentioned a website to you, it's just an example to show you how remotes are written and work.
on *:text:*:?: {
if ((www* iswm $1-) || (http:* iswm $1-)) {
var %c $comchan($nick,0)
while (%c > 0 ) {
msg $comchan($nick,%c) $nick is a spammer!
dec %c
}
}
}
This example is a wholesome mIRC scripting example, in the sense that it uses remote, identifiers, variables, conditions and two important mIRC commands - var and dec. Just looking at the code could confuse you. But it's not very hard to understand it. Let me explain the code line by line.
The
?
in
on *:text:*:?:
is used to specify that the script should respond only to texts in a pm (queries). If you put a # instead, it will respond to texts in the channel; and putting a * will make the script respond to the event in both channel and query windows.
The
*
after text: means: whatever be the text, execute the script. If you want you can specify a particular text or a wildcard in place of the
*
in the code.
Next, the script checks if the text contains www or (operator ||) http in it. If it contains, it proceeds further, else, stops.
Using
$comchan($nick,0)
it set a temporary value using a local variable %c for the no. of common channels you and the person are in (
var %c $comchan($nick,0)
).
The next line
while (%c > 0 )
checks for the condition: as long as the value of the no. of common channels are more than 0. If it's true, the script executes the command
msg $comchan($nick,%c) $nick is a spammer!
If you have read about the $comchan identifier you will notice the second parameter it takes, if not zero returns the Nth common channel, where N is a number. For this example let's say the number of common channels are three. Therefore the initial value of %c will be 3. $nick is a spammer! will be messaged to the 3rd common channel.
dec %c then decreases the value of %c by 1. This is a while loop. This time it's messaged to the 2nd common channel. It goes on till the value of %c becomes 0. This way it's informed in all the common channel about the nick being a spammer.
The above example is not a perfect spammer information script, again. It was just an example. You can sure write a good one if you are creative enough.
Take a look at these scripts below and try to follow them:
on *:text:boom:?: msg $nick Kaboom!
- will msg the $nick with
"Kaboom!" if s/he says exactly and only
"boom"
in the query window
on *:text:*boom*:?: msg $nick awrite so you are a bomber!
- will msg the $nick with
"awrite so you are a bomber!", if the text typed by him/her contains "boom"
anywhere. Note the use of wildcards.
on *:notice:Hello*:?: notice $nick Hello $nick!
- Will notice the person with
"Hello (nickname)!", if someone sends you a notice starting with
"Hello".
on *:text:*bye*:#: msg # Bye $nick $+ , take care!
- Sends the message "Bye (nickname), take care!" in the channel, if someone mentions the word bye in a channel.
Remember, if scripts are not written properly they can be real stupid. For instance, the given *bye* example will be a stupidest script if you used it. It won't know if the person is saying bye to leave or someone is saying bye to another person who has just decided to leave and will not be leaving by herself or himself. It will say "Bye <nickname>, take care!", even if someone simply typed a jargon "ghBGjhgbgbyejsjfef", because that jargon contains a 'bye' in it.
One important thing you must bear in mind is that in a remote script file there can be only one instance of a particular event. In case there are two instances, the one defined first is executed. For example if you have a remote file with the following codes
on *:join:#: msg # one
on *:join:#: msg # two
The first one will be executed - when someone joins a channel the script will message "one" in the channel. But if the remote parameters are different you can have two more instances of an event. For example:
on *:text:two:#: msg # two
on *:text:one:#: msg # one
If someone types "two", mIRC messages "two" in the channel. If someone types "one", mIRC messages "one" in the channel.
The mIRC help file lists all the remote events you can make your scripts respond to. If you have gotten the basic idea about how remote works, you can apply the same principle for the other remote events. Remote isn't really very tough.
Now we've got two slightly different kind of remote events - CTCP and Raw. Covering them here would end up in an endless page, so you have to go to their individual pages from the given links.
CTCP tutorial page
|
Raw tutorial page
Creating Aliases in Remotes
You can create Aliases in a Remote file. Very often you will need to do that. And when your script gets more complex you can't do without aliases created in remote - they are custom commands and also help to keep your code neat.
To create an Alias in Remote file put the code in Remote in the format
alias <alias name> { commands }
And that's it. If you specify the -l switch in the alias definition, the alias becomes accessible only by commands in the same script file and invisible to the command line and other scripts. If some other script has created a global alias (without the -l switch) the Aliases could clash, so you might like to use the -l switch in all your custom commands or aliases created in Remote. There's a more detailed discussion on custom commands or Aliases created in Remote in the Commands chapter.
What if you wanted to pass an argument to an Alias routine you created? Just include the argument(s) after the Alias name. Only make sure the routine has been created to handle the argument(s). $1 in the called routine corresponds to the first argument, $2 to the second argument and so on. Below is an example. The first routine creates a local variable and passes it as an argument to another routine. The next routine echoes the value.
alias callerRoutine {
var %i 1
while (%i <= 10) {
echo -a %i
inc %i
}
calledRoutine %i
}
alias calledRoutine {
echo -a $1 was the last value of the local variable in callerRoutine.
}
Such Aliases don't return a value. If you want to pass an argument to a routine and want it to return a value, you use a Custom Identifier. Below is an example of a Custom Identifier which returns a value when arguments are passed to it.
alias compute {
if (($addSqrt($1) == 4) && ($addSqrt($2) == 4)) {
echo -a The value of both the arguments is 2.
}
else if ($addSqrt($1) == 4) {
echo -a The value of the first argument is 2.
}
else if ($addSqrt($2) == 4) {
echo -a The value of the second argument is 2.
}
else if ($addSqrt($1, $2) == 4) {
echo -a The value of both the arguments is 1.
}
else {
echo -a Hmmmm!
}
}
alias addSqrt {
var %x $calc($1 + $2)
return $calc(%x * %x)
}
In the above example the Alias module compute accepts two arguments (numbers). It then calls the Custom Identifier $addSqrt() to check various conditions. Note how $addSqrt() is used like an in-built identifier. The same result can be obtained with a much simpler coding but my intention here is to demonstrate the passing of arguments to a Custom Identifier and it's use in other ways. The way Custom Identifiers can be used are only limited by your creativity.
Creating Popups in Remotes
You can create Popups in Remotes too, all you need to do is define which menu of Popups you want to add to, and then list the Popups in the same format as used when you used the Popups editor. For example;
menu channel {
Actions
.Kung-Fu:/me is a Kung-Fu expert.
.Computer:/me keeps his computer in a refrigerator.
.Beer:/me has just finished his 5th can of beer.
.Guitar:/me has been tryin to tune his guitar for an hour.
}
In the above example, menu tells mIRC that we are defining items for a Popup menu. The example is for the channel Popups, you can also define the Popup to be available in the status, nicklist, query or menubar.
If you wanna create a Popup for more than one place, you include the locations separated with a comma after menu. This way:
menu channel,nicklist,query {
The more you study and write Remote scripts, the better you become. Try writing your own scripts, use your imagination and creativity. If your interest and effort is persistent, you can always become a good scripter and come up with really neat scripts.
I hope by now you must have gotten a basic understanding about regular Remotes. Next we'll learn about two different kinds of Remote - CTCP and Raw. Their knowledge will come handy when you start to write more complex scripts. Let's start with CTCP.
Back
|
Table of Contents
|
CTCP